﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HPIT_Library_BLL;
using HPIT_Library_Modal;

namespace HPIT_Library
{
    public partial class userAdd : BasePage
    {
        protected  member UserInfo = new member();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int pid = Convert.ToInt32(Request.QueryString["id"]);
                UserInfo = HPIT_Library_BLL.userManger.SelectID(pid);
                if (UserInfo != null)
                {
                    RadioButtonList1.SelectedValue = UserInfo.MemberSex + "";
                    DataBind();
                }
            }
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UserInfo = new member() {
                id = Convert.ToInt32(txtID.Text),
                MemberName = Convert.ToString(txtName.Text),
                MemberPhone=Convert.ToString(txtPhone.Text),
                MemberSex=Convert.ToInt32(RadioButtonList1.SelectedValue),
                MemberSite=Convert.ToString(TextBox1.Text),
                
            };
            if (userManger.Update(UserInfo) >0)
            {
                Response.Redirect("/user.aspx");
            } 
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            member member = new member();
            
           
            var MemberName = txtName.Text.Trim();
            var MemberSex = Convert.ToInt32( RadioButtonList1.SelectedValue);
            var MemberSite = TextBox1.Text;
            var MemberPhone = txtPhone.Text;
            member.MemberName = MemberName;
            member.MemberPhone = MemberPhone;
            member.MemberSex = MemberSex;
            member.MemberSite = MemberSite;

            if (HPIT_Library_BLL.userManger.AddUser(member)>0)
            {
                Response.Write("<script>alert('添加成功！');location.href='user.aspx'</script>");
            }  
        }
    }
}